package com.app.piemoment;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;

public class PieWelcomeActivity extends Activity {

	private DataLoaderTask task;

	private boolean login = true;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);

		if (task != null) {
			task.cancel(true);
			task = null;
		}
		task = new DataLoaderTask();
		task.execute();

	}

	class DataLoaderTask extends AsyncTask<Void, Integer, Long> {

		@Override
		protected Long doInBackground(Void... arg0) {

			for (int i = 0; i < 10; i++) {
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

			}
			return null;
		}

		@Override
		protected void onProgressUpdate(Integer... values) {
			super.onProgressUpdate(values);
		}

		@Override
		protected void onPostExecute(Long result) {
			Intent intent = null;
			if (!login) {
				intent = new Intent(PieWelcomeActivity.this, HomeActivity.class);
				startActivity(intent);
			} else {
				intent = new Intent(PieWelcomeActivity.this,
						LoginUserActivity.class);
				startActivity(intent);
			}

			finish();
			super.onPostExecute(result);
		}

		@Override
		protected void onPreExecute() {
			task = null;
			super.onPreExecute();
		}

	}
}